package rinpu.springtest.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import rinpu.springtest.pojo.entity.Permission;
import rinpu.springtest.pojo.entity.Role;
import rinpu.springtest.mapper.RoleMapper;
import rinpu.springtest.service.PermissionService;
import rinpu.springtest.service.RoleService;

import java.util.Collections;
import java.util.List;

/**
 * @Author Rin_pu
 * @Date 2025/9/21 20:17
 * @Description RoleService
 */
@Service
public class RoleServiceimpl extends ServiceImpl<RoleMapper, Role> implements RoleService {

    @Resource
    private PermissionService permissionService;

    @Override
    public List<Role> getRoleListByUserIds(List<Long> ids) {
        return baseMapper.selectRoleListByUserIds(ids);
    }

    @Override
    public List<Permission> getPermissionByUserId(Long id) {
        List<Long> roleListByUserIds = this.getRoleListByUserIds(Collections.singletonList(id)).stream()
                .map(Role::getId)
                .toList();
        return permissionService.getPermissionListByRoleIds(roleListByUserIds);
    }
}
